package com.jxk.test.service;

import com.jxk.test.event.MyEvent;
import com.jxk.test.entity.Role;
import com.jxk.test.entity.User;
import org.springframework.context.ApplicationContext;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;

/**
 * @ClassName : UserService  //类名
 * @Description :   //描述
 * @Author : jxk  //作者
 * @Date: 2020-09-21 13:59  //时间
 */
@Service
public class UserService {

    @Resource
    private ApplicationContext applicationContext;

    /**
     * 发布事件
     * @return
     */
    public User getUser2() {
        Role role=new Role("管理员");
        Role role1=new Role("普通用户");
        List<Role> roles=new ArrayList<>();
        roles.add(role);
        roles.add(role1);
        User user =new User("jxk","123456",roles);
        // 发布事件 收到触发
        MyEvent event = new MyEvent(this, user);
        applicationContext.publishEvent(event);
        return user;
    }
}
